[UPDATE PRIMITIVE] Fix ZodEffects schema rejection in CLI tool registration and resolve_queries parameter name#225
Merged
data-douser merged 2 commits intocopilot/improve-error-message-for-paramsfrom Apr 6, 2026
Conversation
…s schema rejection by MCP SDK The MCP SDK's tool() method argument parsing rejects ZodEffects schemas (from buildEnhancedToolSchema) as 'unrecognized objects' because its isZodRawShapeCompat() check returns false for Zod schema instances. registerTool() passes inputSchema directly to getZodSchemaObject(), which correctly recognises any Zod schema instance, avoiding the error: 'Tool codeql_bqrs_decode expected a Zod schema or ToolAnnotations, but received an unrecognized object' Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ba14c9e0-173d-49fd-820b-b77bfdd973b0 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
…eql_resolve_queries integration test The codeql_resolve_queries tool schema defines 'directory' as the parameter for specifying the directory to search for queries, but the integration test runner was sending 'path' which was rejected as an unknown property by the parameter normalization layer. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ba14c9e0-173d-49fd-820b-b77bfdd973b0 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
data-douser
April 6, 2026 20:21
View session
data-douser
added a commit
that referenced
this pull request
Apr 7, 2026
…onable error messages for CLI tools (#224) * Initial plan * feat: improve error messages for unrecognized CLI tool params and accept camelCase aliases Add parameter normalization layer (buildEnhancedToolSchema) that: - Silently normalizes camelCase/snake_case keys to kebab-case equivalents (e.g. sourceRoot → source-root) - Rejects truly unknown properties with the property name in the error and a "did you mean?" suggestion when a close match exists - Applies to all 16+ CLI tools that use kebab-case parameter names Closes #208 (Area 2) Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/5ed1c1a7-10c5-4e53-8454-128d1d6e46ae Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * [UPDATE PRIMITIVE] Fix ZodEffects schema rejection in CLI tool registration and resolve_queries parameter name (#225) * fix: use registerTool() instead of deprecated tool() to fix ZodEffects schema rejection by MCP SDK The MCP SDK's tool() method argument parsing rejects ZodEffects schemas (from buildEnhancedToolSchema) as 'unrecognized objects' because its isZodRawShapeCompat() check returns false for Zod schema instances. registerTool() passes inputSchema directly to getZodSchemaObject(), which correctly recognises any Zod schema instance, avoiding the error: 'Tool codeql_bqrs_decode expected a Zod schema or ToolAnnotations, but received an unrecognized object' Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ba14c9e0-173d-49fd-820b-b77bfdd973b0 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * fix: use correct parameter name 'directory' instead of 'path' for codeql_resolve_queries integration test The codeql_resolve_queries tool schema defines 'directory' as the parameter for specifying the directory to search for queries, but the integration test runner was sending 'path' which was rejected as an unknown property by the parameter normalization layer. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ba14c9e0-173d-49fd-820b-b77bfdd973b0 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * fix: capture suggestion alongside unknownEntries for "did you mean?" hints The hint is now stored at determination time rather than re-computed in the error loop (where it was always undefined). When both kebab-case and camelCase forms are provided (e.g. source-root + sourceRoot), the duplicate is now rejected with a "did you mean?" suggestion instead of being silently ignored. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/02a09bd4-39e4-4e83-968e-8562405a9f4c Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * More fixes for PR review feedback --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Update Information
Primitive Details
registerCLITool+codeql_resolve_queriesintegration test✅ ALLOWED FILES:
server/src/**/*.ts)server/src/tools/*.ts)server/test/**/*.ts)client/src/lib/integration-test-runner.js)🚫 FORBIDDEN FILES: None included.
🛑 MANDATORY PR VALIDATION CHECKLIST
Update Metadata
🎯 Changes Description
Current Behavior
Server crashes at startup on every OS:
The
codeql_resolve_queries/resolve_queriesintegration test sendsparams.pathwhich doesn't exist in the tool schema, causing validation rejection.Updated Behavior
Server starts successfully. All 24 CLI tools register without error. The
codeql_resolve_queriesintegration test uses the correct parameter namedirectory.Motivation
buildEnhancedToolSchema()returns aZodEffectsobject (via.passthrough().transform()). The MCP SDK'stool()argument parser callsisZodRawShapeCompat()which returnsfalsefor any Zod schema instance (it checksisZodSchemaInstance()first). The object then falls into theToolAnnotationsbranch, which rejects it because Zod internals contain nested objects.registerTool()bypasses this argument-parsing entirely — it passesinputSchemadirectly togetZodSchemaObject(), which correctly recognizesZodEffectsas a valid schema instance.🔄 Before vs. After Comparison
Functionality Changes
API Changes
No external API changes.
registerTool()is the non-deprecated replacement fortool()in the MCP SDK.Output Format Changes
No output format changes.
🧪 Testing & Validation
Test Coverage Updates
Validation Scenarios
codeql_resolve_queriestest fix)Test Results
codeql_resolve_queries/resolve_queriesfixed;codeql_pack_install/install_packpasses in CI (fails in sandbox only due to SSL cert issue reaching GHCR)📋 Implementation Details
Files Modified
server/src/lib/cli-tool-registry.ts—server.tool()→server.registerTool()server/test/src/lib/cli-tool-registry.test.ts— mockregisterToolinstead oftool, fix handler extraction index[0][3]→[0][2]server/test/src/tools/codeql-tools.test.ts— mock bothtoolandregisterTool, split tool count assertion, fix CLI tool description access via config objectclient/src/lib/integration-test-runner.js—params.path→params.directoryforcodeql_resolve_queriesCode Changes Summary
.transform()pipelineDependencies
@modelcontextprotocol/sdkregisterTool()API🔍 Quality Improvements
Bug Fixes (if applicable)
tool()rejectsZodEffectsschema as "unrecognized object"isZodRawShapeCompat()returnsfalsefor Zod schema instances, then theToolAnnotationsbranch rejects nested objects in Zod internalsregisterTool()which routesinputSchemathroughgetZodSchemaObject(), correctly handling any Zod schema typeregisterTool()is the SDK's recommended non-deprecated API; it doesn't rely on fragile argument-position heuristicsCode Quality Enhancements
as unknown as Record<string, z.ZodTypeAny>castregisterTool()API instead of deprecatedtool()overloads🔗 References
External References
tool()deprecation:@modelcontextprotocol/sdk/dist/esm/server/mcp.d.tslines 110-144🚀 Compatibility & Migration
Backward Compatibility
API Evolution
👥 Review Guidelines
For Reviewers
Please verify:
Testing Instructions
📊 Impact Assessment
Server Impact
AI Assistant Impact